#include "bulletMgr.h"
#include "misc.h"

CBulletMgr::CBulletMgr()
{
	m_nAutoFishID = 0;
}

CBulletMgr::~CBulletMgr()
{
	FishIterator it = m_mBulletMgr.begin();

	for (;it!=m_mBulletMgr.end();it++)
	{
		if (it->second)
		{
			SafeDelete (it->second);
		}
	}

	m_mBulletMgr.clear();
}

void CBulletMgr::Init(CCLayer * pLayer)
{
	m_pScene = pLayer;
}

void CBulletMgr::Create()
{
	CBullet* pTem = new CBullet();
	int id = ++m_nAutoFishID;
	int nType =abs(int((double)rand() / (RAND_MAX + 1) * 2));

	pTem->Init(id,nType,m_pScene);

	AddBullet(pTem);

}

void CBulletMgr::AddBullet(CBullet* pBullet)
{
	m_mBulletMgr[pBullet->GetID()] = pBullet;
}

void CBulletMgr::Update(const ccTime& dt)
{
	FishIterator it = m_mBulletMgr.begin();

	for (;it!=m_mBulletMgr.end();it++)
	{
		it->second->Update(dt);
	}
}